package com.linkai.多线程._05_State;

/**
 * @Description: 测试 Join 方法
 * @Author: 林凯
 * @Date: 2021/10/19 20:17
 */
public class TestJoin implements Runnable {
    @Override
    public void run() {
        for (int i = 0; i < 1000; i++) {
            System.out.println("线程vip来了");
        }
    }

    public static void main(String[] args) throws InterruptedException {
        TestJoin testJoin = new TestJoin();
        Thread thread = new Thread(testJoin);
        thread.start();

        // 主线程
        for (int i = 0; i < 1000; i++) {
            if (i == 200) {
                // 插队；当主线程的 i 为 200 时，让 TestJoin 去执行；执行完了，
                thread.join();      // 插队
            }
            System.out.println("main" + i);
        }
    }
}
